package com.rural.bus.adapter;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rural.bus.R;
import com.rural.bus.model.MyPoiInfo;

public class SearchAddressAdapter extends BaseAdapter {
	private LayoutInflater mInflater;
	private List<MyPoiInfo> mPoiInfos = new ArrayList<MyPoiInfo>();
	
	public SearchAddressAdapter(Context context) {
		mInflater = LayoutInflater.from(context);
	} 
	
	public void appendToList(Collection<? extends MyPoiInfo> infos) {
		mPoiInfos.clear();
		if(infos != null) {
			mPoiInfos.addAll(infos);
		}
		this.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return mPoiInfos.size();
	}

	@Override
	public Object getItem(int position) {
		return mPoiInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null) {
			convertView = mInflater.inflate(R.layout.list_item_search_address, null);
			holder = new ViewHolder();
			holder.tv_address_name = (TextView) convertView.findViewById(R.id.tv_address_name);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		MyPoiInfo poiInfo = mPoiInfos.get(position);
		holder.tv_address_name.setText(""+poiInfo.name);
		return convertView;
	}
	
	static class ViewHolder {
		TextView tv_address_name;
	}

}
